Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thiagodeev/rpcv08-websocket #651

Open
wants to merge 40 commits into
base: v0.8.0
Choose a base branch
from
Open

Conversation

thiagodeev
Copy link
Collaborator

@thiagodeev thiagodeev commented Dec 24, 2024

#623

This PR aims to implement some RPC v0.8.0 updates to starknet.go. The ones addressed by this PR are:

New methods:
starknet_subscribeNewHeads
starknet_subscribeEvents
starknet_subscribeTransactionStatus
starknet_subscribePendingTransactions
starknet_unsubscribe

Components
NEW_TXN_STATUS
REORG_DATA
SUBSCRIPTION_BLOCK_ID

Errors:
INVALID_SUBSCRIPTION_ID
TOO_MANY_ADDRESSES_IN_FILTER
TOO_MANY_BLOCKS_BACK

In order to implement websocket connection with Starknet in starknet.go I had to make some adaptations to the client code being currently used, and to do that, I had to copy the entire client code.

@thiagodeev thiagodeev force-pushed the v0.8.0 branch 2 times, most recently from 61eb5fb to 9199306 Compare January 6, 2025 11:37
…ith Websocket support

- Added gorilla/websocket v1.5.3 as a direct dependency in go.mod.
- Introduced NewWebsocketProvider function in provider.go to create a Websocket RPC Provider instance, enhancing the existing HTTP provider functionality.
- Removed the dependency on github.com/ethereum/go-ethereum and replaced it with github.com/NethermindEth/starknet.go/client in go.mod and related files.
- Introduced new WebSocket provider functionality in provider.go
- Updated the handler to correctly process subscription IDs for Starknet, accommodating the new structure returned by the Starknet API.
- Modified the subscriptionResult struct to include a Starknet-specific subscription ID field.
- Adjusted the WebSocket provider to support new block header subscriptions, improving the overall subscription mechanism.
- Updated example usage to reflect changes in subscription handling and error management.

These changes improve compatibility with Starknet's API and enhance the robustness of the WebSocket client.
- Updated the main CI workflow to include testing for the client with mocks.
- Modified subscription handling in `subscription.js` to accommodate the new `subscription_id` structure from Starknet.
- Refactored `provider_test.go` to include WebSocket provider support and improved test configurations.
- Introduced a new test file `websocket_test.go` to validate WebSocket subscriptions for new block headers, ensuring robust error handling and compatibility with the testnet environment.

These changes improve the overall robustness of the RPC client and enhance compatibility with Starknet's API.
@thiagodeev thiagodeev force-pushed the thiagodeev/rpcv08-websocket branch from f846bb8 to 05d7e90 Compare January 13, 2025 16:49
@thiagodeev thiagodeev force-pushed the thiagodeev/rpcv08-websocket branch from 4bb568c to c73bfce Compare January 13, 2025 22:37
Note: at the moment it's not possible to omit optional parameters in json-rpc calls using array as structure type with Juno, and the current client implementation only supports sending parameters as arrays. Therefore, I changed the Subscribe function and now we are able to send optional parameters as object too. That way Juno doesn't return an error
…hanced error handling and testing

- Added the SubscribeEvents method to the WebSocket provider, allowing for event subscriptions with optional parameters.
- Introduced a new test case in websocket_test.go to validate event subscriptions under various conditions, including handling of empty arguments and specific address filtering.
- Updated the HexToFeltNoErr utility function to convert hexadecimal strings to felt objects without error handling, suitable for internal use.

These changes improve the robustness of the WebSocket client and enhance compatibility with Starknet's event subscription model.
utils/Felt.go Outdated Show resolved Hide resolved
account/account_test.go Outdated Show resolved Hide resolved
rpc/types_event.go Outdated Show resolved Hide resolved
rpc/websocket.go Outdated Show resolved Hide resolved
rpc/websocket.go Outdated Show resolved Hide resolved
rpc/websocket.go Outdated Show resolved Hide resolved
rpc/websocket.go Outdated Show resolved Hide resolved
@thiagodeev thiagodeev marked this pull request as ready for review January 30, 2025 05:19
rpc/websocket_test.go Outdated Show resolved Hide resolved
rpc/websocket_test.go Outdated Show resolved Hide resolved
rpc/websocket_test.go Outdated Show resolved Hide resolved
rpc/websocket_test.go Outdated Show resolved Hide resolved
rpc/websocket_test.go Outdated Show resolved Hide resolved
rpc/websocket_test.go Outdated Show resolved Hide resolved
rpc/websocket_test.go Outdated Show resolved Hide resolved
rpc/websocket_test.go Outdated Show resolved Hide resolved
rpc/websocket_test.go Outdated Show resolved Hide resolved
rpc/websocket_test.go Outdated Show resolved Hide resolved
rpc/websocket_test.go Outdated Show resolved Hide resolved
@thiagodeev thiagodeev force-pushed the thiagodeev/rpcv08-websocket branch from b5806b2 to abfd00e Compare February 11, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants